package ruifeng.zcj.happymahjony.other;

import android.graphics.Bitmap;
import android.webkit.JavascriptInterface;

import ruifeng.zcj.happymahjony.listener.IsOpenSound;

/**
 * 邀请与分享JS接口<br/>
 */
public class JSInterface {

    private JSListener listener;

    public void setShareListener(JSListener listener) {
        this.listener = listener;
    }

    /**
     * 点击微信邀请好友即时回调<br/>
     * param:参数如mid=304&token=4f165a455c5b188d56cbd3d1f2708d65&role=host&rid=863<br/>
     * room:房间号<br/>
     */
    @JavascriptInterface
    public void jsCallJava(String room) {
//        System.out.println("zcj" + room);
        listener.invite(null, room);
    }

    /**
     * 分享好友即时回调<br/>
     */
    @JavascriptInterface
    public void jsCallJava2() {
        listener.share("1",null);
    }

    /**
     * 分享朋友圈<br/>
     */
    @JavascriptInterface
    public void jsCallJava3() {
        listener.shareCircle(null);
    }

    @JavascriptInterface
    public void startRecord() {
        listener.startRecord();
    }

    @JavascriptInterface
    public void finishRecord(String arg) {
        listener.finishRecord(arg);
    }

    @JavascriptInterface
    public void cancelRecord() {
        listener.cancelRecord();
    }

    @JavascriptInterface
    public void playCard(String name) {
        listener.playCard(name);
    }

    @JavascriptInterface
    public void exitLogin() {
        listener.exitLogin();
    }

    @JavascriptInterface
    public void playRecord(String name) {
        listener.playRecord(name);
    }


    @JavascriptInterface
    public void controlBgm(String name) {
        listener.controlBgm(name);
    }

    @JavascriptInterface
    public void controlSound(String name) {
        if (IsOpenSound.isSound)
            listener.controlSound(name);
    }

    @JavascriptInterface
    public void shareAchievement() {
        listener.shareAchievement();
    }


    public interface JSListener {

        void invite(String param, String room);

        void share(String text, Bitmap bitmap);

        void shareCircle(String text);

        void startRecord();

        void finishRecord(String arg);

        void cancelRecord();

        void playCard(String name);

        void playRecord(String name);

        void exitLogin();

        void controlBgm(String arg);

        void controlSound(String arg);

        void shareAchievement();
    }

}
